package com.atom.process.cnmuseum.cj.dao.task;

import java.util.Date;
import java.util.List;

import org.springframework.stereotype.Repository;

import com.atom.common.dao.AvensCommonDao;
import com.atom.common.exception.AvensNullPointerException;
import com.atom.common.remote.user.UserUtil;
import com.atom.process.cnmuseum.cj.entity.task.CjTaskDO;

@Repository
public class CjTaskDao extends AvensCommonDao<CjTaskDO> {

  public CjTaskDO findByTaskId(String taskId) {
    List<CjTaskDO> list = super.findByProperty("taskId", taskId);
    if (list == null || list.size() == 0) {
      throw new AvensNullPointerException("TaskDO is null where taskId = " + taskId);
    } else {
      return list.get(0);
    }
  }
  
  public void createADO(UserUtil user, String processInstanceId, String taskId, String biaoTi) {
    CjTaskDO ado = new CjTaskDO();
    ado.setShenQingRen(user.getUserid());
    ado.setShenQingRenText(user.getUsername());
    ado.setShenQingBuMen(user.getOrgid());
    ado.setShenQingBuMenText(user.getOrgname());
    ado.setShenQingRiQi(new Date());
    ado.setProcessId(processInstanceId);
    ado.setTaskId(taskId);
    ado.setBiaoTi(biaoTi);
    save(ado);
  }

}
